package com.handpay.nocardpay.baselibrary.main.mine.view.fragment;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.commbase.BaseProtocolKey;
import com.handpay.nocardpay.baselibrary.commbase.view.fragment.BaseFragment;
import com.handpay.nocardpay.baselibrary.config.SecureManager;
import com.handpay.nocardpay.baselibrary.main.mine.view.ILimitView;
import com.handpay.nocardpay.baselibrary.main.mine.model.bean.DayLimit;
import com.handpay.nocardpay.baselibrary.main.mine.presenter.MinePresenterImpl;
import com.handpay.nocardpay.baselibrary.utils.AccountUtils;
import com.handpay.nocardpay.baselibrary.utils.ClientEngine;
import com.handpay.nocardpay.baselibrary.utils.CommonUtils;

import java.util.HashMap;

/**
 * Created by sxshi on 2017/8/14.
 */

public class DayLimitFragment extends BaseFragment implements ILimitView {
    private TextView day_transfer_limit;
    private TextView month_transfer_limit;
    private TextView single_debit_card_limit;
    private TextView single_credit_limit;
    private TextView dayTotal_transfer_limit;
    private TextView monthTotal_transfer_limit;
    private TextView singleIC_debit_card_limit;
    private TextView singleIC_credit_limit;

    private MinePresenterImpl minePresenter;
    private HashMap<String, Object> paramers;

    public static DayLimitFragment newInstance() {

        Bundle args = new Bundle();

        DayLimitFragment fragment = new DayLimitFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_limit;
    }

    @Override
    public void initView(View view) {
        Toolbar mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
        initToolbar(mToolbar, true);

        day_transfer_limit = (TextView) view.findViewById(R.id.day_transfer_limit);
        month_transfer_limit = (TextView) view.findViewById(R.id.month_transfer_limit);
        single_debit_card_limit = (TextView) view.findViewById(R.id.single_debit_card_limit);
        single_credit_limit = (TextView) view.findViewById(R.id.single_credit_limit);
        dayTotal_transfer_limit = (TextView) view.findViewById(R.id.dayTotal_transfer_limit);
        monthTotal_transfer_limit = (TextView) view.findViewById(R.id.monthTotal_transfer_limit);
        singleIC_debit_card_limit = (TextView) view.findViewById(R.id.singleIC_debit_card_limit);
        singleIC_credit_limit = (TextView) view.findViewById(R.id.singleIC_credit_limit);

    }

    @Override
    public String getFragmentTitle() {
        return getString(R.string.mine_limit);
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData(Bundle savedInstanceState) {
        minePresenter = new MinePresenterImpl(_mActivity);
        minePresenter.setmLimitView(this);
        paramers = new HashMap<>();
        paramers.put(BaseProtocolKey.PHONE, SecureManager.getInstance().des(AccountUtils.getAccountPhone(_mActivity), 1, null));
        paramers.put(BaseProtocolKey.ACCOUNT, SecureManager.getInstance().des(AccountUtils.getAccountName(_mActivity), 1, null));
        paramers.put(BaseProtocolKey.CHANNEL, ClientEngine.getInstance().CHANNEL);
        paramers.put(BaseProtocolKey.APPCODE, BaseProtocolKey.APPCODE_TRANSFER);
        minePresenter.queryLimit(paramers,true);
    }

    @Override
    public void querySuccess(DayLimit dayLimit) {
        day_transfer_limit.setText(CommonUtils.formatMoney(Double.parseDouble(dayLimit.getDayLimit()) / 100));
        month_transfer_limit.setText(CommonUtils.formatMoney(Double.parseDouble(dayLimit.getMonthLimit()) / 100));
        single_debit_card_limit.setText(CommonUtils.formatMoney(Double.parseDouble(dayLimit.getDebitCardLimit()) / 100));
        single_credit_limit.setText(CommonUtils.formatMoney(Double.parseDouble(dayLimit.getCreditCardLimit()) / 100));
        dayTotal_transfer_limit.setText(CommonUtils.formatMoney(Double.parseDouble(dayLimit.getDayLimit()) / 100));
        monthTotal_transfer_limit.setText(CommonUtils.formatMoney(Double.parseDouble(dayLimit.getMonthLimit()) / 100));
        singleIC_debit_card_limit.setText(CommonUtils.formatMoney(Double.parseDouble(dayLimit.getIcDebitCardLimit()) / 100));
        singleIC_credit_limit.setText(CommonUtils.formatMoney(Double.parseDouble(dayLimit.getIcCreditCardLimit()) / 100));
    }
}
